package com.example.tool.listener;

import com.example.tool.actions.BuildGroup;
import com.example.tool.actions.ConfigAction;
import com.example.tool.actions.OpenDirAction;
import com.example.tool.actions.build.ColumnAction;
import com.example.tool.actions.build.ControllerAction;
import com.example.tool.actions.build.HtmlAction;
import com.example.tool.actions.build.ListenerAction;
import com.example.tool.actions.build.MenuAction;
import com.example.tool.actions.build.SpringConfigAction;
import com.example.tool.actions.build.controls.BtnAction;
import com.example.tool.actions.build.controls.Form3Action;
import com.example.tool.actions.build.controls.Form4Action;
import com.example.tool.actions.build.flow.EventAction;
import com.example.tool.actions.build.flow.NodeAction;
import com.example.tool.actions.build.group.ControlsGroup;
import com.example.tool.actions.build.group.FlowGroup;
import com.example.tool.actions.build.group.LoginGroup;
import com.example.tool.actions.build.group.QuartzGroup;
import com.example.tool.actions.build.group.RestGroup;
import com.example.tool.actions.build.group.TriggerGroup;
import com.example.tool.actions.build.group.UtilGroup;
import com.example.tool.actions.build.login.CustomAction;
import com.example.tool.actions.build.login.SsoInAction;
import com.example.tool.actions.build.login.TripartiteAction;
import com.example.tool.actions.build.quartz.QuartzAction;
import com.example.tool.actions.build.quartz.TimerAction;
import com.example.tool.actions.build.rest.InterfaceAction;
import com.example.tool.actions.build.rest.OutAction;
import com.example.tool.actions.build.rest.RestUtilAction;
import com.example.tool.actions.build.trigger.Trigger3Action;
import com.example.tool.actions.build.trigger.Trigger4Action;
import com.example.tool.actions.build.util.AddressBookAction;
import com.example.tool.actions.build.util.DaoAction;
import com.example.tool.actions.build.util.DateAction;
import com.example.tool.actions.build.util.DenseAction;
import com.example.tool.actions.build.util.IbmMQAction;
import com.example.tool.actions.build.util.MessageAction;
import com.example.tool.actions.build.util.OtherAction;
import com.example.tool.actions.build.util.OutDaoAction;
import com.example.tool.actions.build.util.WebServiceClientAction;
import com.example.tool.actions.build.util.XmlAction;
import com.example.tool.window.HToolWindowConfigAction;
import com.intellij.ide.AppLifecycleListener;
import com.intellij.ide.plugins.DynamicPluginListener;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.Anchor;
import com.intellij.openapi.actionSystem.Constraints;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.actionSystem.Separator;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.PluginId;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class HToolListener implements AppLifecycleListener, DynamicPluginListener {
  private static final Logger LOG = Logger.getInstance(HToolListener.class);

  @Override
  public void appFrameCreated(@NotNull List<String> commandLineArgs) {
    LOG.info("SeeyonTool菜单初始化开始");
    ConfigAction configAction = new ConfigAction();
    OpenDirAction openDirAction = new OpenDirAction();
    SpringConfigAction springConfigAction = new SpringConfigAction();
    HtmlAction htmlAction = new HtmlAction();
    ControllerAction controllerAction = new ControllerAction();
    ColumnAction columnAction = new ColumnAction();
    MenuAction menuAction = new MenuAction();
    ListenerAction listenerAction = new ListenerAction();
    OutAction outAction = new OutAction();
    RestUtilAction restUtilAction = new RestUtilAction();
    InterfaceAction interfaceAction = new InterfaceAction();
    QuartzAction quartzAction = new QuartzAction();
    TimerAction timerAction = new TimerAction();
    EventAction eventAction = new EventAction();
    NodeAction nodeAction = new NodeAction();
    SsoInAction ssoInAction = new SsoInAction();
    CustomAction customAction = new CustomAction();
    TripartiteAction tripartiteAction = new TripartiteAction();
    Trigger3Action trigger3Action = new Trigger3Action();
    Trigger4Action trigger4Action = new Trigger4Action();
    BtnAction btnAction = new BtnAction();
    Form3Action form3Action = new Form3Action();
    Form4Action form4Action = new Form4Action();
    XmlAction xmlAction = new XmlAction();
    IbmMQAction ibmMQAction = new IbmMQAction();
    DateAction dateAction = new DateAction();
    MessageAction messageAction = new MessageAction();
    DenseAction denseAction = new DenseAction();
    AddressBookAction addressBookAction = new AddressBookAction();
    DaoAction daoAction = new DaoAction();
    OutDaoAction outDaoAction = new OutDaoAction();
    WebServiceClientAction webServiceClientAction = new WebServiceClientAction();
    OtherAction otherAction = new OtherAction();
    HToolWindowConfigAction hToolWindowConfigAction = new HToolWindowConfigAction();
    // 注册菜单
    ActionManager actionManager = ActionManager.getInstance();
    PluginId pluginId = PluginId.getId("tool.xxon.top");
    actionManager.registerAction(ConfigAction.class.getName(), configAction, pluginId);
    actionManager.registerAction(OpenDirAction.class.getName(), openDirAction, pluginId);
    actionManager.registerAction(ControllerAction.class.getName(), controllerAction, pluginId);
    actionManager.registerAction(HtmlAction.class.getName(), htmlAction, pluginId);
    actionManager.registerAction(ColumnAction.class.getName(), columnAction, pluginId);
    actionManager.registerAction(MenuAction.class.getName(), menuAction, pluginId);
    actionManager.registerAction(ListenerAction.class.getName(), listenerAction, pluginId);
    actionManager.registerAction(OutAction.class.getName(), outAction, pluginId);
    actionManager.registerAction(RestUtilAction.class.getName(), restUtilAction, pluginId);
    actionManager.registerAction(InterfaceAction.class.getName(), interfaceAction, pluginId);
    actionManager.registerAction(QuartzAction.class.getName(), quartzAction, pluginId);
    actionManager.registerAction(TimerAction.class.getName(), timerAction, pluginId);
    actionManager.registerAction(EventAction.class.getName(), eventAction, pluginId);
    actionManager.registerAction(NodeAction.class.getName(), nodeAction, pluginId);
    actionManager.registerAction(SsoInAction.class.getName(), ssoInAction, pluginId);
    actionManager.registerAction(CustomAction.class.getName(), customAction, pluginId);
    actionManager.registerAction(TripartiteAction.class.getName(), tripartiteAction, pluginId);
    actionManager.registerAction(Trigger3Action.class.getName(), trigger3Action, pluginId);
    actionManager.registerAction(Trigger4Action.class.getName(), trigger4Action, pluginId);
    actionManager.registerAction(BtnAction.class.getName(), btnAction, pluginId);
    actionManager.registerAction(Form3Action.class.getName(), form3Action, pluginId);
    actionManager.registerAction(Form4Action.class.getName(), form4Action, pluginId);
    actionManager.registerAction(DateAction.class.getName(), dateAction, pluginId);
    actionManager.registerAction(MessageAction.class.getName(), messageAction, pluginId);
    actionManager.registerAction(XmlAction.class.getName(), xmlAction, pluginId);
    actionManager.registerAction(IbmMQAction.class.getName(), ibmMQAction, pluginId);
    actionManager.registerAction(DenseAction.class.getName(), denseAction, pluginId);
    actionManager.registerAction(AddressBookAction.class.getName(), addressBookAction, pluginId);
    actionManager.registerAction(DaoAction.class.getName(), daoAction, pluginId);
    actionManager.registerAction(OutDaoAction.class.getName(), outDaoAction, pluginId);
    actionManager.registerAction(WebServiceClientAction.class.getName(), webServiceClientAction, pluginId);
    actionManager.registerAction(OtherAction.class.getName(), otherAction, pluginId);
    actionManager.registerAction(HToolWindowConfigAction.class.getName(), hToolWindowConfigAction, pluginId);
    // 添加菜单
    DefaultActionGroup projectViewPopupMenu = (DefaultActionGroup) actionManager.getAction("ProjectViewPopupMenu");
    Constraints constraints = new Constraints(Anchor.BEFORE, "CutCopyPasteGroup");
    projectViewPopupMenu.addAction(configAction, constraints);
    projectViewPopupMenu.addAction(openDirAction, constraints);
    BuildGroup group = new BuildGroup();
    group.add(springConfigAction);
    group.add(htmlAction);
    group.add(controllerAction);
    group.add(columnAction);
    group.add(menuAction);
    group.add(listenerAction);
    RestGroup restGroup = new RestGroup();
    restGroup.add(outAction);
    restGroup.add(interfaceAction);
    restGroup.add(restUtilAction);
    group.add(restGroup);
    QuartzGroup quartzGroup = new QuartzGroup();
    quartzGroup.add(quartzAction);
    quartzGroup.add(timerAction);
    group.add(quartzGroup);
    FlowGroup flowGroup = new FlowGroup();
    flowGroup.add(eventAction);
    flowGroup.add(nodeAction);
    group.add(flowGroup);
    LoginGroup loginGroup = new LoginGroup();
    loginGroup.add(ssoInAction);
    loginGroup.add(customAction);
    loginGroup.add(tripartiteAction);
    group.add(loginGroup);
    TriggerGroup triggerGroup = new TriggerGroup();
    triggerGroup.add(trigger3Action);
    triggerGroup.add(trigger4Action);
    group.add(triggerGroup);
    ControlsGroup controlsGroup = new ControlsGroup();
    controlsGroup.add(btnAction);
    controlsGroup.add(form3Action);
    controlsGroup.add(form4Action);
    group.add(controlsGroup);
    UtilGroup utilGroup = new UtilGroup();
    utilGroup.add(dateAction);
    utilGroup.add(messageAction);
    utilGroup.add(xmlAction);
    utilGroup.add(ibmMQAction);
    utilGroup.add(denseAction);
    utilGroup.add(addressBookAction);
    utilGroup.add(daoAction);
    utilGroup.add(outDaoAction);
    utilGroup.add(webServiceClientAction);
    utilGroup.add(otherAction);
    group.add(utilGroup);
    projectViewPopupMenu.add(group, constraints);
    projectViewPopupMenu.addAction(Separator.create(), constraints);
    AppLifecycleListener.super.appFrameCreated(commandLineArgs);
    LOG.info("SeeyonTool菜单初始化结束");
  }
}
